# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from fastapi import APIRouter, Request
from hypertext import R, response_json
from apps.admin.schemas import login_schema as schema
from apps.admin.service.login_service import LoginService

router = APIRouter(prefix="/login", tags=["登录系统"])


@router.get("/captcha", summary="登录验证码", response_model=R[schema.LoginCaptchaVo])
@response_json
async def captcha(request: Request):
    client_ip = request.client.host
    return await LoginService.captcha(client_ip)


@router.post("/check", summary="登录验证", response_model=R[schema.LoginSuccessVo])
@response_json
async def check(request: Request, params: schema.LoginCheckIn):
    return await LoginService.check(request, params)


@router.post("/logout", summary="退出系统", response_model=R)
@response_json
async def logout(request: Request):
    token: str = request.headers.get("Authorization", "")
    await LoginService.logout(token.strip("Bearer "))
